using System.Text.RegularExpressions;

namespace Project_Schedule.Utilities;

public static class StringExtension
{
    /// <summary>
    /// 获取int
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static int GetInt(this object obj)
    {
        if (obj == null)
            return 0;
        int.TryParse(obj.ToString(), out int _number);
        return _number;
    }
    /// <summary>
    /// 获取bool
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static bool GetBool(this string value)
    {
        bool.TryParse(value, out bool result);
        return result;
    }
    /// <summary>
    /// 判定手机号
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static bool IsPhoneNo(this string value)
    {
        return Regex.IsMatch(value, 
            "^(0\\d{2,3}-?\\d{7,8}(-\\d{3,5}){0,1})|(((13[0-9])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8})$");
    }
}